import java.util.*;

interface IntegerStack{
	public Integer push(Integer item);
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty(); 
	public int size(); 

}

class ArrayIntegerStack implements IntegerStack{
	Integer[] Stack; 
	private static int top=0;
	public ArrayIntegerStack(int n){
		Stack = new Integer[n];
	}

	@Override
	public Integer push(Integer item) {
		if(item == null||this.size()>=Stack.length)
			return null;
		this.Stack[this.top]=item;
		this.top++;
		return item;
	}

	@Override
public Integer pop() {
		if(this.empty())
			return null;
		if(this.top-1==0){
			this.top--;
			return null;
		}
			
		this.top--;
		return Stack[this.top-1];
	}

	@Override
	public Integer peek() {
		if(this.empty())
			return null;
		return Stack[this.top-1];
	}

	

	@Override
	public boolean empty() {
		if(top==0)
			return true;
		return false;
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return this.top;
	}
	
}

public class Week07_7_3 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in 

);
		ArrayIntegerStack a = new ArrayIntegerStack(sc.nextInt());
		int m = sc.nextInt();
		for(int i=0;i<m;i++)
		{
			System.out.println(a.push(sc.nextInt()));
		}
		System.out.println(a.peek()+","+a.empty()+","+a.size());
		System.out.println(Arrays.toString(a.Stack));
		int x = sc.nextInt();
		for(int i=0;i<x;i++){
			System.out.println(a.peek());
			a.pop();
		}
		System.out.println(a.peek()+","+a.empty()+","+a.size());
		System.out.println(Arrays.toString(a.Stack));


	}

}